package net.lab1024.sa.admin.module.business.yuqing.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import net.lab1024.sa.admin.module.business.yuqing.domain.form.NewsArticleQueryForm;
import net.lab1024.sa.admin.module.business.yuqing.domain.vo.NewsArticleExcelVO;
import net.lab1024.sa.admin.module.business.yuqing.domain.vo.NewsArticleVO;
import net.lab1024.sa.admin.module.business.yuqing.service.NewsArticleService;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.ValidateList;
import net.lab1024.sa.base.common.util.SmartExcelUtil;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 舆情文章 Controller
 *
 * @Author 1024创新实验室: 卓大
 * @Date 2025-01-15 10:00:00
 * @Wechat zhuda1024
 * @Email lab1024@163.com
 * @Copyright  <a href="https://1024lab.net">1024创新实验室</a>
 */
@RestController
@Tag(name = "舆情监测管理")
public class NewsArticleController {

    @Resource
    private NewsArticleService newsArticleService;

    @Operation(summary = "分页查询舆情文章 @author 卓大")
    @PostMapping("/yuqing/article/query")
    @SaCheckPermission("yuqing:article:query")
    public ResponseDTO<PageResult<NewsArticleVO>> queryPage(@RequestBody @Valid NewsArticleQueryForm queryForm) {
        return newsArticleService.queryPage(queryForm);
    }

    @Operation(summary = "获取文章详情 @author 卓大")
    @GetMapping("/yuqing/article/detail/{articleId}")
    @SaCheckPermission("yuqing:article:detail")
    public ResponseDTO<NewsArticleVO> getDetail(@PathVariable Long articleId) {
        return newsArticleService.getDetail(articleId);
    }

    @Operation(summary = "删除文章 @author 卓大")
    @DeleteMapping("/yuqing/article/delete/{articleId}")
    @SaCheckPermission("yuqing:article:delete")
    public ResponseDTO<String> delete(@PathVariable Long articleId) {
        return newsArticleService.delete(articleId);
    }

    @Operation(summary = "批量删除文章 @author 卓大")
    @PostMapping("/yuqing/article/batchDelete")
    @SaCheckPermission("yuqing:article:delete")
    public ResponseDTO<String> batchDelete(@RequestBody @Valid ValidateList<Long> articleIds) {
        return newsArticleService.batchDelete(articleIds);
    }

    @Operation(summary = "导出文章数据 @author 卓大")
    @PostMapping("/yuqing/article/export")
    @SaCheckPermission("yuqing:article:export")
    public void exportData(@RequestBody NewsArticleQueryForm queryForm, HttpServletResponse response) throws IOException {
        List<NewsArticleExcelVO> dataList = newsArticleService.exportData(queryForm);
        SmartExcelUtil.exportExcel(response, "舆情文章数据.xlsx", "舆情文章", NewsArticleExcelVO.class, dataList);
    }

    @Operation(summary = "导入文章数据 @author 卓大")
    @PostMapping("/yuqing/article/import")
    @SaCheckPermission("yuqing:article:import")
    public ResponseDTO<String> importData() {
        return newsArticleService.importNewsData();
    }
} 